<!doctype html>
<html>
<!--
author:guojunyu
date:2019-05-22
desc:this demo is about blog. PLEASE NOTE:If you have trouble running it ,try any of the other demos or connect with auther.
A ny individuals and organizations and not for commercial use, professiona website for customized web site.
-->
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="shortcut icon" href="/static/images/bitbug_favicon.ico" type="image/x-icon" />
  <link href="/static/css/base.css" rel="stylesheet">
  <link href="/static/css/index.css" rel="stylesheet">
  <link href="/static/css/m.css" rel="stylesheet">
  <script src="/static/js/jquery.min.js" type="text/javascript"></script>
  <script src="/static/js/jquery.easyfader.min.js"></script>
  <script src="/static/js/scrollReveal.js"></script>
  <script src="/static/js/common.js"></script>
</head>

<body>
</body>

<script>

    token = window.localStorage.getItem('dnblog_token');
    username = window.localStorage.getItem('dnblog_user')
    var url = document.location.toString();
    var arrUrl = url.split("//");
    //当前访问的博客博主
    var blog_username = arrUrl[1].split('/')[1];
    var topic_release_url = '/' + blog_username + '/' + 'topic/release';
    var user_info_url = '/' + blog_username + '/' + 'info';
    var html_body = '';
    $.ajax({
        // 请求方式
        type:"get",
        // url
        url:"http://127.0.0.1:8080/topic/content/"+ username + '/',
        beforeSend: function(request) {
            request.setRequestHeader("Authorization", token);
        },
        success:function (result) {
            if (200 == result.code){
                alert("请求成功");
                console.log(result);
                $(document).attr('title', '文章列表-'+ result.data.nickname+'的博客');
                html_body += '<header id="header">';
                html_body += '<div class="menu">';
                html_body += ' <nav class="nav" id="topnav"> ';
                html_body += '<h1 class="logo"><a href="index.html"> ' + result.data.nickname + '的博客</a></h1>';
                html_body += '<li><a href="index.html">网站首页</a></li>';
                html_body += '<li>';
                html_body += '<a href="list.html">文章列表</a>';
                html_body += '<ul class="sub-nav">';
                html_body += '<li><a href="list.html">Python</a></li>';
                html_body += '<li><a href="list.html">python Web</a></li>';
                html_body += '<li><a href="list.html">爬虫</a></li>';
                html_body += '<li><a href="list.html">JS实例索引</a></li>';
                html_body += '</ul>';
                html_body += '</li>';
                html_body += '<li><a href="photo.html">我的相册</a> </li>';
                html_body += '<li><a href=' + '"' + user_info_url + '"' + '>关于我</a> </li>';
                html_body += '<li><a href=' + '"' + topic_release_url + '"' + '>发表博客</a> </li>';
                html_body += '</nav>';
                html_body += '</div>';
                if (token){
                    html_body += '<li><a href= /' + username + '/change_info id="change_info" target="_blank">编辑</a></li>';
                    html_body += '<li><a href="" id="login_out" target="_blank">登出</a></li>';
                }else{
                //检查 session
                    html_body += '<a href="/login" id="login" target="_blank">登陆</a>';
                    html_body += '<a href="register.html" id="register" target="_blank">注册</a>';
                }
                html_body += '</header>';
                html_body += '<div class="container">';
                html_body += '<div class="pagebg re"></div>';
                html_body += '<div class="container">';
                html_body += '<h1 class="t_nav"><span>不要轻易放弃。学习成长的路上，我们长路漫漫，只因学无止境。 </span>';

                html_body += '<p class="n1">发表博客</p>';
                html_body += '</h1>';
                html_body += '<div class="blogsbox">';
                html_body += '<br>';
                var topics = result.data.topics
                if(topics.length == 0){
                    html_body += '空空如也'

                } else {

                    for(var t in topics){

                        var title = topics[t].title;
                        var category = topics[t].category;
                        var created_time = topics[t].created_time;
                        var introduce = topics[t].introduce;
                        var author = topics[t].author;
                        html_body += '<div class="blogsbox">';
                        html_body += '<div class="blogs" data-scroll-reveal="enter bottom over 1s">';
                        html_body += '<h3 class="blogtitle"><a href="info.html" target="_blank">' + title + '</a></h3>';
                        html_body += '<p class="blogtext">';
                        html_body += introduce;
                        html_body += '...</p>'
                        //html_body += '<p class="blogtext">'+ '12345' + '...</p>';
                        html_body += '<div class="bloginfo">';
                        html_body += '<ul>';
                        html_body += '<li class="author">' + author + '</li>';
                        html_body += '<li class="timer">' + created_time +  '</li>';
                        html_body += '</ul>';
                        html_body += '</div>';
                        html_body += '</div>';
                        html_body += '</div>';
                    }

                }

                html_body += '</div>';
                $('body').html(html_body);
                //初始化scroll
                scrollReveal.init();

                //test
                $('.nav>li').hover(function () {
                    $(this).children('ul').stop(true, true).show(400);
                }, function () {
                    $(this).children('ul').stop(true, true).hide(400);
                });

            }else{
                alert(result.error)
            }
          }
      });

</script>

</html>
